// pages/home/pages/party1RelationGo/party1RelationGo.js
var r = require('../../../../utils/request.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    disabled:false,
    id:'',

    partyName: '',
    sex: '',
    sexName: '请选择性别',
    age:'',
    birthday:'',
    nation: '', //民族
    idcard: '', //身份证号
    nativeAddress: '', //籍贯
    nativePlace: '', //户籍所在地
    address: '', //现居住地
    telephone: '', //联系方式

    school: '',
    education: '',
    major: '',
    academic: '',

    relaPartyNo: '', //党号
    joinTime: '', //入党时间
    relaPost: '', //党内职务
    becomeTime: '', //转正时间
    relaAddress: '', //档案所在地
    relaUnit: '', //档案所在单位
    relaWork: '', //工作岗位
    relaWitness: '', //证明人
    relaPhone:'',//证明人联系方式
  },

  // 性别
  getSex() {
    if(this.data.disabled){
      return
    }
    var that = this
    wx.showActionSheet({
      itemList: ['男', '女'],
      success: function (res) {
        // console.log(res.tapIndex)
        if (res.tapIndex == 0) {
          that.setData({
            sexName: '男',
            sex: 'M'
          })
        } else {
          that.setData({
            sexName: '女',
            sex: 'F'
          })
        }
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },

  // 获取值
  getval(e) {
    let num = e.currentTarget.dataset.num
    if (num == 1) {
      this.setData({
        partyName: e.detail.value
      })
    } else if (num == 2) {
      this.setData({
        nation: e.detail.value
      })
    } else if (num == 3) {
      this.setData({
        idcard: e.detail.value
      })
    } else if (num == 4) {
      this.setData({
        nativeAddress: e.detail.value
      })
    } else if (num == 5) {
      this.setData({
        nativePlace: e.detail.value
      })
    } else if (num == 6) {
      this.setData({
        address: e.detail.value
      })
    } else if (num == 7) {
      this.setData({
        telephone: e.detail.value
      })
    } else if (num == 8) {
      this.setData({
        school: e.detail.value
      })
    } else if (num == 9) {
      this.setData({
        education: e.detail.value
      })
    } else if (num == 10) {
      this.setData({
        major: e.detail.value
      })
    } else if (num == 11) {
      this.setData({
        academic: e.detail.value
      })
    } else if (num == 12) {
      this.setData({
        relaPartyNo: e.detail.value
      })
    } else if (num == 14) {
      this.setData({
        relaPost: e.detail.value
      })
    }else if (num == 15) {
      this.setData({
        relaPhone: e.detail.value
      })
    } else if (num == 16) {
      this.setData({
        relaAddress: e.detail.value
      })
    } else if (num == 17) {
      this.setData({
        relaUnit: e.detail.value
      })
    } else if (num == 18) {
      this.setData({
        relaWork: e.detail.value
      })
    } else if (num == 19) {
      this.setData({
        relaWitness: e.detail.value
      })
    }else if(num == 20){
      this.setData({
        age:e.detail.value
      })
    }
  },

  //入党时间
  bindDateChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    let num = e.currentTarget.dataset.num
    if(num == 1){
      this.setData({
        joinTime: e.detail.value
      })
    }else if(num == 2){
      this.setData({
        becomeTime: e.detail.value
      })
    }else if(num == 3){
      this.setData({
        birthday: e.detail.value
      })
    }
  },

  // 所属驿站
  // bindPickerChange: function (e) {
  //   var that = this
  //   // console.log('picker发送选择改变，携带值为', e)
  //   if (that.data.array.length == 0) {
  //     return
  //   }
  //   that.setData({
  //     index: e.detail.value,
  //     station: that.data.array[e.detail.value].id,
  //   })
  // },

  submit(){
    let param = {
      id:this.data.id,
      relaStatus:0,
      partyName: this.data.partyName,
      age:this.data.age,
      sex: this.data.sex,
      birthday:this.data.birthday,
      nation: this.data.nation, //民族
      idcard: this.data.idcard, //身份证号
      nativeAddress: this.data.nativeAddress, //籍贯
      nativePlace: this.data.nativePlace, //户籍所在地
      address: this.data.address, //现居住地
      telephone: this.data.telephone, //联系方式
      school: this.data.school,
      education: this.data.education,
      major: this.data.major,
      academic: this.data.academic,
      relaPartyNo: this.data.relaPartyNo, //党号
      joinTime: this.data.joinTime, //入党时间
      relaPost: this.data.relaPost, //党内职务
      becomeTime: this.data.becomeTime, //转正时间
      relaAddress: this.data.relaAddress, //档案所在地
      relaUnit: this.data.relaUnit, //档案所在单位
      relaWork: this.data.relaWork, //工作岗位
      relaWitness: this.data.relaWitness, //证明人
      relaPhone:this.data.relaPhone
    }
    r.toPost('/dwBranchRelationship/shipAdd', param, (res) => {
      wx.showToast({
        title: '操作成功',
        icon:'none'
      })
      setTimeout(function(){
        wx.navigateBack({
          delta: 1,
        })
      },800)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    r.toPost('/dwBranchRelationship/shipDetail', {relaStatus:0}, (res) => {
      if(!res.retData || res.retData.length == 0){
        this.setData({
          disabled:false,
          id:''
        })
      }else{
        this.setData({
          disabled:true,
          id:res.retData.id,
          partyName: res.retData.partyName,
          age:res.retData.age,
          sex: res.retData.sex,
          sexName: res.retData.sexName,
          birthday: res.retData.birthday,
          nation: res.retData.nation, //民族
          idcard: res.retData.idcard, //身份证号
          nativeAddress: res.retData.nativeAddress, //籍贯
          nativePlace: res.retData.nativePlace, //户籍所在地
          address: res.retData.address, //现居住地
          telephone: res.retData.telephone, //联系方式
          school: res.retData.school,
          education: res.retData.education,
          major: res.retData.major,
          academic: res.retData.academic,
          relaPartyNo: res.retData.relaPartyNo, //党号
          joinTime: res.retData.joinTime, //入党时间
          relaPost: res.retData.relaPost, //党内职务
          becomeTime: res.retData.becomeTime, //转正时间
          relaAddress: res.retData.relaAddress, //档案所在地
          relaUnit: res.retData.relaUnit, //档案所在单位
          relaWork: res.retData.relaWork, //工作岗位
          relaWitness: res.retData.relaWitness, //证明人
          relaPhone:res.retData.relaPhone
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})